package redis.inaction.xx.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import redis.inaction.xx.env.EnvStrategyFactoryBean;
import redis.inaction.xx.env.RedisCacheTimeConfig;

@Configuration
public class XXConfiguration {

    @Bean
    public EnvStrategyFactoryBean envStrategyFactoryBean(
            @Value("${cacheClosed:false}") boolean cacheClosed,
            @Value("${ignoreRefererCheck:true}") boolean ignoreRefererCheck,
            Environment env){
        String[] profiles = env.getActiveProfiles();
        return new EnvStrategyFactoryBean(cacheClosed, ignoreRefererCheck, profiles.length == 0 ? null : profiles[0]);
    }

    @Bean
    public RedisCacheTimeConfig redisCacheTimeConfig(){
        return new RedisCacheTimeConfig();
    }

}
